package com.xk.school_device.common;

/**
 * @Title: Result
 * @Author xk
 * @Package com.xk.school_device.common
 * @Date 2025/4/16 11:33
 * @description: 返回体
 */
public class Result {
    private Integer code;
    private String message;
    private Object data;

    // 默认构造函数
    public Result() {
    }

    // 带参数的构造函数
    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // Getter 和 Setter 方法
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    // 成功返回，带消息
    public static Result success(String message) {
        return new Result(200, message, null);
    }

    // 成功返回，带数据
    public static Result success(Object data) {
        return new Result(200, "success", data);
    }

    // 成功返回，带消息和数据
    public static Result success(String message, Object data) {
        return new Result(200, message, data);
    }

    // 失败返回，带消息
    public static Result failure(String message) {
        return new Result(500, message, null);
    }

    // 失败返回，带状态码和消息
    public static Result failure(Integer code, String message) {
        return new Result(code, message, null);
    }
}


